package gttp.nspa.client.adm.ui;

import gttp.nspa.client.adm.place.BillingListPlace;
import gttp.nspa.client.adm.place.CustomerListPlace;

import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.toolbar.FillToolItem;
import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem;
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;

public class NsShell implements IsWidget, AcceptsOneWidget {

    private final BorderLayoutContainer root = new BorderLayoutContainer();
    private final LabelToolItem         title;
    private final ContentPanel          pane;

    @Inject
    private PlaceController             placec;

    NsShell() {
        ToolBar tb = new ToolBar();
        tb.setSpacing(4);
        tb.add(new TextButton("Home", new SelectHandler() {

            public void onSelect(SelectEvent event) {
                placec.goTo(new BillingListPlace(true));
            }
        }));
        tb.add(new TextButton("Customers", new SelectHandler() {

            public void onSelect(SelectEvent event) {
                placec.goTo(new CustomerListPlace(true));
            }
        }));

        tb.add(new FillToolItem());
        title = new LabelToolItem();
        tb.add(title);

        root.setNorthWidget(tb, new BorderLayoutData(40));
        pane = new ContentPanel();
        pane.setHeaderVisible(false);
        root.setCenterWidget(pane);
    }

    public void setWidget(IsWidget w) {
        if (w == null)
            return;

        title.setLabel(w.toString());
        pane.setWidget(w);
        root.forceLayout();
    }

    public Widget asWidget() {
        return root;
    }
}
